﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Skybot.Docs
{
    /// <summary>
    /// 近义词的处理缓存
    /// </summary>
    public  class WordUnitys
    {
        /// <summary>
        /// 记录文件名
        /// </summary>
        protected string RecordFile = AppDomain.CurrentDomain.BaseDirectory + "App_Data/records.txt";

        /// <summary>
        /// 近义词处理缓存
        /// </summary>
        private WordUnitys()
        {
            //如果文件存在
            if (System.IO.File.Exists(RecordFile))
            {
                _Caches = (
                    from x in System.IO.File.ReadAllLines(RecordFile)
                    select new WordEntity(x)
                    //排序 字符越长的排除在越前面
                    ).OrderByDescending(p=>p.OriginWord.Length)
                    //过滤重复
                    .ToLookup(p=>p.OriginWord)
                    .Select(p=>p.FirstOrDefault())
                    .ToList();
            }
        }

        private static readonly WordUnitys instance = new WordUnitys();

        /// <summary>
        /// 数据访问实例
        /// </summary>
        public static WordUnitys Instance
        {
            get { return WordUnitys.instance; }
        } 



        private   List<WordEntity> _Caches = new List<WordEntity>();
        /// <summary>
        /// 缓存数据功能
        /// </summary>
        public  List<WordEntity> Caches
        {
            get { 
                return _Caches; }
        } 


    }
}